<?php

namespace Modules\Market\Entities;

use Modules\Core\Entities\BaseEntity as Model;
use ThrowException;

// use Modules\Core\Traits\Likeable;

class Tenant extends Model
{
	// use Likeable;

    protected $guarded = [];
    protected $table = 'market_tenants';

    static public $resourceName = '集市商户';

    protected $casts = [
    ];

    public function user()
    {
    	return $this->belongsTo('\Modules\User\Entities\User', 'user_id');
    }

    // 我购买的转售
    public function resales()
    {
        return $this->hasMany('\Modules\Asset\Entities\Resale', 'tenant_id');
    }

    public function updateStat()
    {
        return $this->update([
            'product_total' => $this->resales()->sum('product_total'),
            'money_total' => $this->resales()->sum('money_price'),
            'score_total' => $this->resales()->sum('score_price'),
        ]);
    }
}
